package asf.sections
{
	import asf.core.Application;
	import asf.core.BaseLoadable;
	import asf.core.Layer;
	import asf.events.PopupEvent;
	import asf.interfaces.IPopup;
	import asf.log.LogLevel;
	
	import com.adobe.utils.StringUtil;

	[Event( type="asf.events.PopupEvent", name="hideEnd" )]

	public class Popup extends BaseLoadable
	{
		private var baseNode:XML;
		private var app:Application;
		
		public var view:IPopup;
		
		public function Popup( p_baseNode:XML, p_app:Application )
		{
			super( p_app );
			
			baseNode = p_baseNode;
			this.rawXML = baseNode;
			app = p_app;
		}
		
		public function get application( ):Application
		{
			return app;
		}
		
		public function notifyHideEnd( ):void
		{
			app.log( id, LogLevel.INFO_3 );
			this.dispatchEvent( new PopupEvent( PopupEvent.HIDE_END ) );
		}
		
		public function load( ):void
		{
			var dfile:String = dictionaryFile;
			var depend:XMLList = baseNode.copy( ).dependencies;
			
			app.log( this.id, LogLevel.INFO_3 );
			
			if( dfile != "" )
			{
				depend.file += new XML( this.formatDependencyNode( "$_dict_0", dfile, "xml" ) );
			}
			
			this.initDependencies( depend, baseNode.@useOwnContext == "true" );
		}
		
		public function get canBlur( ):Boolean
		{
			var blur:String = app.getParsedValueOf( baseNode.@blur || baseNode.blur );
			return blur == "true";
		}
		
		public function get darkLayer( ):Layer
		{
			var darkName:String = StringUtil.trim( app.getParsedValueOf( baseNode.@darkLayer || baseNode.darkLayer ) );
			if( darkName == "" ) return null;
			
			return app.layers.getLayer( darkName ); 
		}
		
		public function get darkAmount( ):Number
		{
			var darkString:String = StringUtil.trim( app.getParsedValueOf( baseNode.@darkAmount || baseNode.darkAmount ) );
			if( darkString == "" ) darkString = "0.2";
			
			return parseFloat( darkString );
		}
		
		public function get lock( ):Boolean
		{
			return app.getParsedValueOf( String( baseNode.@lock ) || String( baseNode.lock ) ) != "false"; 
		}
		
		private function get dictionaryFile( ):String
		{
			return app.getParsedValueOf( baseNode.@dictionaryfile || baseNode.dictionaryfile );
		}
		
		public function get id( ):String
		{
			return app.getParsedValueOf( baseNode.@id || baseNode.id );
		}
		
		public function get closeOnNavigate( ):Boolean
		{
			return app.getParsedValueOf( baseNode.@closeOnNavigate || baseNode.closeOnNavigate ) == "true";
		}
		
		public function get viewClassName( ):String
		{
			return app.getParsedValueOf( baseNode.@viewClass || baseNode.viewClass );
		}
		
		public function get margin_top( ):int
		{
			return parseInt( app.getParsedValueOf( baseNode.@margin_top || baseNode.margin_top ) );
		}
		
		public function get extras( ):XMLList
		{
			return baseNode.extras;
		}
		
		public function get margin_bottom( ):int
		{
			return parseInt( app.getParsedValueOf( baseNode.@margin_bottom || baseNode.margin_bottom ) );
		}
		
		public function get margin_left( ):int
		{
			return parseInt( app.getParsedValueOf( baseNode.@margin_left || baseNode.margin_left ) );
		}
		
		public function get margin_right( ):int
		{
			return parseInt( app.getParsedValueOf( baseNode.@margin_right || baseNode.margin_right ) );
		}
	}
}